/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mahumLogs.model;

import com.mahumLogs.backedbeans.Promotion;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author apo
 */
public class PromotionDataModel extends ListDataModel<Promotion> implements SelectableDataModel<Promotion> {

    /**
     * Constructeur vide
     */
    public PromotionDataModel() {
        
    }

    /**
     * @param list 
     */
    public PromotionDataModel(List<Promotion> list) {
        super(list);
    }

    /**
     * @param prom
     * @return libelle d'une promotion prom
     */
    @Override
    public Object getRowKey(Promotion prom) {
       return prom.getLibelle();
    }

    /**
     * @param rowKey
     * @return Promotion
     */
    @Override
    public Promotion getRowData(String rowKey) {
             List<Promotion> promotions = (List<Promotion>) getWrappedData();

        for(Promotion prom : promotions) {
            if(prom.getLibelle().equals(rowKey))
                return prom;
        }
        return null;
    }
}
